<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">
<header>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <title></title>

        <link href="/assets/images/favicon.ico" rel="icon">
        <link rel="stylesheet" href="/assets/libs/layui/css/layui.css" />
        <link rel="stylesheet" href="/assets/module/admin.css?v=318" />

        <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
        <script type="text/javascript" src="/assets/libs/layui/layui.js"></script>
        <script type="text/javascript" src="/assets/js/common.js?v=318"></script>

        <style>
            .model-form-footer {
                text-align: center;
            }
        </style>

        <script type="text/javascript">
            var url = window.location.pathname.substring(1);
            var item = url.split("/");
            var C = item[0];
            var A = item[1];
            var cUrl = "/" + C;
        </script>
    </head>
</header>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">

            <form class="layui-form model-form">
                <input type="hidden" name="id" th:value="${model.id}">
                <!-- 培训项目 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">培训项目</label>
                    <div class="layui-input-block">
                        <input type="text" name="projectName" required lay-verify="required"  autocomplete="off" class="layui-input" th:value="${model.projectName}" th:readonly="${model.currentUser.role!='二级学院用户'}">
                    </div>
                </div>

                <!-- 二级单位 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">二级单位</label>
                    <div class="layui-input-block">
                        <input type="text" name="department" required lay-verify="required"  autocomplete="off" class="layui-input" th:value="${model.department}" th:readonly="${model.currentUser.role!='二级学院用户'}">
                    </div>
                </div>

                <!-- 诊断背景 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">诊断背景</label>
                    <div class="layui-input-block">
                        <textarea name="background" placeholder="请输入诊断背景" class="layui-textarea" required lay-verify="required" th:text="${model.background}" th:readonly="${model.currentUser.role!='二级学院用户'}"></textarea>
                    </div>
                </div>

                <!-- 诊断目的 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">诊断目的</label>
                    <div class="layui-input-block">
                        <textarea name="target" placeholder="请输入诊断目的" class="layui-textarea" required lay-verify="required" th:text="${model.target}" th:readonly="${model.currentUser.role!='二级学院用户'}"></textarea>
                    </div>
                </div>

                <!-- 诊断区域与对象 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">诊断区域与对象</label>
                    <div class="layui-input-block">
                        <input type="text" name="object" required lay-verify="required"  autocomplete="off" class="layui-input" th:value="${model.object}" th:readonly="${model.currentUser.role!='二级学院用户'}">
                    </div>
                </div>

                <!-- 诊断内容 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">诊断内容</label>
                    <div class="layui-input-block">
                        <textarea name="content" placeholder="请输入诊断内容" class="layui-textarea" required lay-verify="required" th:text="${model.content}" th:readonly="${model.currentUser.role!='二级学院用户'}"></textarea>
                    </div>
                </div>

                <!-- 诊断方法 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">诊断方法</label>
                    <div class="layui-input-block">
                        <textarea name="method" placeholder="请输入诊断方法" class="layui-textarea" required lay-verify="required" th:text="${model.method}" th:readonly="${model.currentUser.role!='二级学院用户'}"></textarea>
                    </div>
                </div>

                <!-- 诊断流程 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">诊断流程</label>
                    <div class="layui-input-block">
                        <textarea name="flow" placeholder="请输入诊断流程" class="layui-textarea" required lay-verify="required" th:text="${model.flow}" th:readonly="${model.currentUser.role!='二级学院用户'}"></textarea>
                    </div>
                </div>

                <!-- 预期诊断成果 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">预期诊断成果</label>
                    <div class="layui-input-block">
                        <textarea name="result" placeholder="请输入预期诊断成果" class="layui-textarea" required lay-verify="required" th:text="${model.result}" th:readonly="${model.currentUser.role!='二级学院用户'}"></textarea>
                    </div>
                </div>

                <!-- 人员组织分工 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">人员组织分工</label>
                    <div class="layui-input-block">
                        <textarea name="person" placeholder="请输入人员组织分工" class="layui-textarea" required lay-verify="required" th:text="${model.person}" th:readonly="${model.currentUser.role!='二级学院用户'}"></textarea>
                    </div>
                </div>

                <!-- 日程安排 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">日程安排</label>
                    <div class="layui-input-block">
                        <textarea name="schedule" placeholder="请输入日程安排" class="layui-textarea" required lay-verify="required" th:text="${model.schedule}" th:readonly="${model.currentUser.role!='二级学院用户'}"></textarea>
                    </div>
                </div>

                <!-- 文档版本 -->
<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label">文档版本</label>-->
<!--                    <div class="layui-input-block">-->
<!--                        <input type="number" name="version" required lay-verify="required" placeholder="请输入文档版本" autocomplete="off" class="layui-input" th:value="${model.version}" th:readonly="${model.currentUser.role!='二级学院用户'}">-->
<!--                    </div>-->
<!--                </div>-->

                <!-- 审批状态 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">审批状态</label>
                    <div class="layui-input-block">
                        <select name="state" th:disabled="${model.currentUser.role!='管理员'}">
                            <option th:value="0" th:text="修改" th:selected="${model.state == 0}"></option>
                            <option th:value="1" th:text="通过" th:selected="${model.state == 1}"></option>
                            <option th:value="2" th:text="未提交" th:selected="${model.state == null || model.state!= 0 && model.state!= 1}"></option>
                        </select>
                    </div>
                </div>

                <!-- 审批意见 -->
                <div class="layui-form-item">
                    <label class="layui-form-label">审批意见(管理员审核)</label>
                    <div class="layui-input-block">
                        <textarea name="advice" class="layui-textarea" required lay-verify="required" th:text="${model.advice}" th:readonly="${model.currentUser.role!='管理员'}"></textarea>
                    </div>
                </div>

                <!-- 审批时间 -->
                <div class="layui-form-item" th:hidden="${model.confirmDate == null or model.confirmDate == ''}">
                    <label class="layui-form-label">审批时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="confirmDate"
                               th:value="${#dates.format(model.confirmDate, 'yyyy-MM-dd')}"
                               required lay-verify="required" autocomplete="off" class="layui-input" readonly>
                    </div>
                </div>

                <!-- 审批人 -->
                <div class="layui-form-item" th:hidden="${model.confirmUser.userName == null or model.confirmUser.userName == ''}">
                    <label class="layui-form-label">审批人</label>
                    <div class="layui-input-block">
                        <input type="text" name="confirmUser.userName" required lay-verify="required"  autocomplete="off" class="layui-input" th:value="${model.confirmUser.userName}" th:hidden="${model.confirmUser == null}" readonly>
                        <!-- 隐藏的输入字段，用于传递整个 confirmUser 对象 -->
                        <input type="hidden" name="confirmUser.id" th:value="${model.confirmUser.id}" />
                        <input type="hidden" name="confirmUser.realName" th:value="${model.confirmUser.realName}" />
                        <input type="hidden" name="confirmUser.userPwd" th:value="${model.confirmUser.userPwd}" />
                        <input type="hidden" name="confirmUser.role" th:value="${model.confirmUser.role}" />
                        <input type="hidden" name="confirmUser.tel" th:value="${model.confirmUser.tel}" />
                        <input type="hidden" name="confirmUser.email" th:value="${model.confirmUser.email}" />
                    </div>
                </div>

                <div class="layui-form-item text-center model-form-footer">
                    <button class="layui-btn" lay-submit lay-filter="saveDocSchemeForm"
                            th:classappend="${model.state == 1 ? ' layui-btn-disabled' : ''}"
                            th:disabled="${model.state == 1}">提交上报</button>
                    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
                    <button class="layui-btn layui-btn-warm" id="exportWord" type="button">导出 Word</button>
                    <button class="layui-btn layui-btn-danger" id="exportPdf" type="button">导出 PDF</button>
                </div>
            </form>
            <script src="/assets/libs/jquery/jquery-3.2.1.min.js"></script>
            <script>
                $(function () {
                    console.log('ready');
                    layui.use(['form', 'layer'], function () {
                        //var $ = layui.jquery;
                        var layer = layui.layer;
                        var form = layui.form;
                        console.log(form)
                        var index = parent.layer.getFrameIndex(window.name);//获取窗口索引
                        parent.layer.iframeAuto(index);
                        console.log('load!');
                        var index = parent.layer.getFrameIndex(window.name);//获取窗口索引

                        $('#exportWord').on('click', function () {
                            var id = $('input[name="id"]').val(); // 获取表单的ID
                            window.location.href = '/project/scheme_exportWord/' + id;
                        });

                        $('#exportPdf').on('click', function () {
                            var id = $('input[name="id"]').val(); // 获取表单的ID
                            window.location.href = '/project/scheme_exportPdf/' + id;
                        });

                        form.on('submit(saveDocSchemeForm)', function (data) {
                            $.ajax({
                                type: 'POST',
                                url: "/project/saveDoc_Scheme",
                                contentType: 'application/json',  // 设置为 JSON 格式
                                data: JSON.stringify(data.field), // 将表单数据转换为 JSON 字符串
                                success: function (res) {
                                    console.log(res)
                                    if (res.code === 0) {
                                        console.log("res: " + res);
                                        // 调用父窗口方法
                                        // 调用父窗口方法
                                        $('#search',parent.document).click();
                                        parent.layer.msg('上报成功');
                                        parent.layer.close(index);

                                        layer.msg('保存成功');

                                    } else {
                                        layer.msg(res.msg, {
                                            icon: 2,
                                            anim: 6
                                        });

                                    }
                                }
                            });
                            return false;
                        })

                    });

                });
            </script>


        </div>
    </div>
</div>

<footer>
    <!-- JS部分 -->
    <script type="text/javascript">
        var url = window.location.pathname.substring(1);
        var item = url.split("/");
        var jsUrl = "/static/module/javaweb_" + item[0] + ".js";
        document.write("<script src='" + jsUrl + "'><\/script>");
    </script>
</footer>
</body>
</html>
